﻿using Sustainalytics.Entities.RiskRatings;

namespace Sustainalytics.ScreeningTool.Synchronization.Handlers.RiskRatings
{
    public static class RiskRatingIndicatorExtensions
    {
        public static string GetIndicatorKey(this RiskRatingIndicatorBase entity, MaterialIssueType? materialIssueType = null)
            => materialIssueType != MaterialIssueType.BaselineIssue
                ? GetIndicatorKey(entity.IndicatorType, entity.Code, entity.Name)
                : entity.Name;

        public static string GetIndicatorKey(this (IndicatorType IndicatorType, string Code, string Name) entity)
            => GetIndicatorKey(entity.IndicatorType, entity.Code, entity.Name);

        private static string GetIndicatorKey(IndicatorType indicatorType, string code, string name)
          => indicatorType == IndicatorType.StandardIndicator ? $"{code} {name}" : name;

        public static object GetAnswerCategory(this RiskRatingIndicatorBase entity)
            => entity.IndicatorType == IndicatorType.StandardIndicator
                ? (object)entity.AnswerCategoryText
                : entity.AnswerCategory;
    }
}
